package com.sanqing.action;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.sanqing.base.action.BaseAction;
import com.sanqing.po.User;
import com.sanqing.service.UserService;

@Results({ @Result(name = "adminLogin", location = "/admin/index.jsp"), 
	       @Result(name = "agentgin", location = "/agent/index.jsp"), 
	       @Result(name = "shoperLogin", location = "/shoper/index.jsp"), 
	       @Result(name = "noLogin", location = "/login.jsp") })
public class LoginAction extends BaseAction<User> {

	private static final long serialVersionUID = 4021216916917177796L;

	private User user = new User();
	@Autowired
	private UserService userService;

	@Override
	public String list() throws Exception {
		if ("1".equals(user.getUserType())) {
			User u = userService.login(user.getAccount(), user.getPassword(), user.getUserType());
			if(u!=null){
				return "adminLogin";
			}else{
				addActionError("该工号不存在，或者密码不正确!");
				return "noLogin";
			}			
		}else if ("2".equals(user.getUserType())) {
			
			return "agentgin";
		}else {
			return "shoperLogin";
		}
		
//		 else {
//			if ("1".equals(user.getUserType())) {
//				addActionError("该工号不存在，或者密码不正确!");
//			} else {
//				addActionError("该工号不存在，或者密码不正确!");
//			}
//			return "noLogin";
//
//		}
	}

	@Override
	public User getModel() {
		return user;
	}

}
